import type { CodeType, type, UserData } from '@/types/user'
import { request } from '@/utils/http'

interface userType {
  password: string
  mobile: string
}

export interface userType2 {
  mobile: string
  code: string
}

export const loginByPassAPI = (obj: userType) => {
  return request.post<null, type>('/login/password', obj)
}

/**
 *
 * @param mobile 手机号
 * @param type 验证类型
 * @returns Promise<number>
 */
export const getCodeAPI = (mobile: string, type: CodeType) => {
  return request.get<null, { code: string }>('/code', {
    params: {
      mobile: mobile,
      type: type,
    },
  })
}

export const loginByCodeAPI = (obj: userType2) => {
  return request.post<null, type>('/login', obj)
}

export const userInfoApi = () => {
  return request.get<null, UserData>('/patient/myUser')
}
